import { defineConfig } from "vite";
import { resolve } from "path";
import vue from "@vitejs/plugin-vue";
import { viteStaticCopy } from "vite-plugin-static-copy";


// 定义页面入口对象
const pages = {
  main: resolve(__dirname, "./index.html"), // 主页面
  popup: resolve(__dirname, "./popup.html"), // 弹窗页面
  background: resolve(__dirname, "./src/background.ts"),
  content: resolve(__dirname, "./src/content.ts"),
};
const output = () => {
  return {
    assetFileNames: '[ext]/[name]-[hash].[ext]',
    entryFileNames: (chunkInfo: any) => {
      if (["background", "content"].includes(chunkInfo.name)) {
        return '[name].js';
      }
      return 'js/[name].js';
    },
    chunkFileNames: (chunkInfo: any) => {
      if (["background", "content"].includes(chunkInfo.name)) {
        return '[name].js';
      }
      return `js/[name]-[hash].js`;
    },
    manualChunks: (path: string) => {
      if (path.includes("src/background.ts")) {
        return "background";
      }
      if (path.includes("src/content.ts")) {
        return "content";
      }
    },
  };
};
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  plugins: [
    vue(),
    viteStaticCopy({
      targets: [
        {
          src: "manifest.json",
          dest: ".",
        },
      ],
    })
  ],
  build: {
    rollupOptions: {
      input: pages,
      output: output(),
    },
    minify: true,
  },
});


